package LeetCode;

import java.util.Stack;

/**
 * @ClassName My
 * @Description TODO
 * @Author ZJX
 * @Date 2024/9/18 20:56
 * @Version 1.0
 */
class MyQueue {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (stack2.isEmpty()){
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    // 获取队列头部元素
    public int peek() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    // 检查队列是否为空
    public boolean empty() {
        return stack1.isEmpty() && stack2.isEmpty();
    }
}

